home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Delphi Magazine Collection 2001
/
Delphi Magazine Collection 20001 (2001).iso
/
DISKS
/
ISSUE23
/
SURVIVE
/
fmpymt.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1997-05-19
|
5KB
|
188 lines
unit fmpymt;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, DB, MultGrid, Mask,
fmAllo, uAllo;
type
TfrmPayment = class(TForm)
grpOutstandingCredits: TGroupBox;
grpPayment: TGroupBox;
grdPayment: TStringGrid;
grpTotals: TGroupBox;
edtTotalToPay: TEdit;
edtTotalPaid: TEdit;
edtBalanceDue: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
btnPost: TButton;
btnCancel: TButton;
dsCreditsOut: TDataSource;
btnAllocation: TButton;
grdCredits: TDBMultiGrid;
btnSelectAll: TButton;
btnClearAll: TButton;
procedure FormDestroy(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure grdCreditsSelected(Sender: TObject);
procedure grdPaymentSetEditText(Sender: TObject; ACol, ARow: Longint;
const Value: string);
procedure btnSelectAllClick(Sender: TObject);
procedure btnClearAllClick(Sender: TObject);
procedure btnAllocationClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
public
CustomerNo: LongInt;
TotalToPay,
TotalPaid,
BalanceDue: Double;
AllocationInfo: TAllocationInfo;
procedure PopulateForm;
procedure UpdateTotals;
end;
var
frmPayment: TfrmPayment;
function ShowCreditPaymentDlg(aCustomerNo: LongInt): TModalResult;
implementation
{$R *.DFM}
uses
uBase, dmData;
function ShowCreditPaymentDlg(aCustomerNo: LongInt): TModalResult;
begin
Application.CreateForm(TfrmPayment, frmPayment);
try
with frmPayment do begin
CustomerNo := aCustomerNo;
PopulateForm;
Result := ShowModal;
end;
finally
frmPayment.Release;
end;
end;
procedure TfrmPayment.PopulateForm;
var
I: Integer;
begin
UpdateTotals;
{ Show the outstanding credits for this customer }
with dmDataModule.qryCreditsOutByCustomer do begin
ParamByName('CustNo').AsInteger := CustomerNo;
Open;
end;
{ Setup the payment method grid }
with grdPayment do begin
Cells[0, 0] := 'Method';
Cells[1, 0] := 'Amount';
with dmDataModule.PaymentMethodsList do begin
RowCount := Count + 1;
for I := 0 to Count - 1 do
Cells[0, I + 1] := Strings[I];
end;
end;
end;
procedure TfrmPayment.UpdateTotals;
begin
if TotalToPay = 0 then
BalanceDue := 0
else
BalanceDue := TotalToPay - TotalPaid;
edtTotalToPay.Text := Format(mskCurrency, [TotalToPay]);
edtTotalPaid.Text := Format(mskCurrency, [TotalPaid]);
edtBalanceDue.Text := Format(mskCurrency, [BalanceDue]);
if BalanceDue < 0 then
edtBalanceDue.Color := clRed
else
edtBalanceDue.Color := TGroupBox(edtBalanceDue.Parent).Color;
end;
procedure TfrmPayment.FormCreate(Sender: TObject);
begin
AllocationInfo := TAllocationInfo.Create;
end;
procedure TfrmPayment.FormDestroy(Sender: TObject);
begin
dmDataModule.qryCreditsOutByCustomer.Close;
AllocationInfo.Free;
end;
procedure TfrmPayment.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TfrmPayment.grdCreditsSelected(Sender: TObject);
var
DeltaAmount: LongInt;
begin
(* if PaymentAllocation.Allocated then PaymentDeallocated := True;*)
DeltaAmount := dmDataModule.qryCreditsOutByCustomer.FieldByName('BalanceDue').AsInteger;
if not grdCredits.Selected then DeltaAmount := -DeltaAmount;
TotalToPay := TotalToPay + DeltaAmount;
UpdateTotals;
with dmDataModule.qryCreditsOutByCustomer do
if grdCredits.Selected then
AllocationInfo.Credits.Add(FieldByName('CreditNo').AsInteger,
Trunc(FieldByName('BalanceDue').AsFloat))
else
AllocationInfo.Credits.Delete(FieldByName('CreditNo').AsInteger);
end;
procedure TfrmPayment.grdPaymentSetEditText(Sender: TObject; ACol,
ARow: Longint; const Value: string);
var
I: Integer;
V: Integer;
begin
{ Update total payment amount }
TotalPaid := 0;
if Value = '' then V := 0
else V := StrToInt(Value);
with grdPayment do begin
AllocationInfo.MethodAmounts[ARow - FixedRows] := V;
for I := 1 to RowCount do
if Cells[1, I] <> '' then
TotalPaid := TotalPaid + StrToFloat(Cells[1, I]);
end;
UpdateTotals;
end;
procedure TfrmPayment.btnSelectAllClick(Sender: TObject);
begin
grdCredits.SelectAll(True);
end;
procedure TfrmPayment.btnClearAllClick(Sender: TObject);
begin
grdCredits.SelectAll(False);
end;
procedure TfrmPayment.btnAllocationClick(Sender: TObject);
begin
ShowPaymentAllocationDlg(AllocationInfo);
end;
end.